package com.xl.rentkeeper.entity;

import com.squareup.wire.Wire;
import com.xl.fuse.protos.viewroom.ViewOrder;
import com.xl.rentkeeper.db.orm.DBObj;
import com.xl.rentkeeper.db.orm.DBObjBase;
import com.xl.rentkeeper.db.orm.dsl.ConflictClause;
import com.xl.rentkeeper.db.orm.dsl.Ignore;
import com.xl.rentkeeper.db.orm.dsl.UniqueConstraints;

import java.io.Serializable;

/**
 * Created by Administrator on 2015/8/19.
 */
@UniqueConstraints(columnNames = "id", clause = ConflictClause.REPLACE)
public class Order extends DBObjBase implements DBObj,Serializable{
    public Order(){

    }
    public Order(ViewOrder viewOrder){
        this.id = viewOrder.id;
        this.status = viewOrder.status;
        this.createTime = viewOrder.createTime;
        this.updateTime = viewOrder.updateTime;
        this.signTime = viewOrder.signTime;
        this.contractEntryTime = viewOrder.contractEntryTime;
        this.orderTime = viewOrder.orderTime;
        this.viewTime = viewOrder.viewTime;
        this.orderStewardTime = viewOrder.orderStewardTime;
        this.viewOrder = viewOrder;
    }
    static Wire wire = new Wire();
    public byte[] data;
    public int id;
    public int status;
    public long createTime;
    public long updateTime;
    public long signTime;
    public long contractEntryTime;
    public long orderTime;
    public long viewTime;
    public long orderStewardTime;

    @Ignore
    public String tag;
    @Ignore
    public String timeoutLength;
    @Ignore
    public ViewOrder viewOrder;

    @Override
    public void preSave() {
        if (viewOrder != null) {
            data = viewOrder.toByteArray();
        } else {
            data = null;
        }
    }

    @Override
    public void afterLoad() {
        if (data != null) {
            try {
                viewOrder = wire.parseFrom(data,ViewOrder.class);
            } catch (Exception e) {
                e.printStackTrace();
                viewOrder = null;
            }
        }
    }
}
